//
//  JkmCellStatus.swift
//  SinaWb
//
//  Created by Jiang on 5/26/16.
//  Copyright © 2016 Jiang. All rights reserved.
//

import UIKit

class JkmCellStatus: NSObject {
    
    init(data: CellDataModel) {
        super.init()
        dataModel = data
        
        /// 设置头像
        if let url = NSURL(string: (dataModel!.UserInfo?.profile_image_url)!){
            iconImageURL = url
        }
        
        /// 设置会员等级
        if let level = dataModel!.UserInfo?.mbrank where level > 0 {
            
            let MimageName = "common_icon_membership_level\(level)"
            
            ViplevelImage =  UIImage(named: MimageName)
        }
        
        /// 设置认证类型
        if let verified = dataModel!.UserInfo?.verified_type  where verified != -1{
            switch verified {
            case 1:
                verifiedImage = UIImage(named: "avatar_enterprise_vip")
            case 2,3,5:
                verifiedImage = UIImage(named: "avatar_grassroot")
            case 220,0:
                verifiedImage = UIImage(named: "avatar_vip")
            default:
                break
            }
        }
        
        /// 设置来源
        if let comeFrom : NSString = dataModel!.source where comeFrom != ""{
            
            let startLocation = comeFrom.rangeOfString(">").location + 1
            let endLocation = comeFrom.rangeOfString("</").location
            let length = endLocation - startLocation
            let getFromString = comeFrom.substringWithRange(NSRange.init(location: startLocation, length: length))
            comeFromStirng =  "来自 \(getFromString)"
        }
        
        
        /// 设置信息创建时间
        if let timeString  = dataModel!.created_at {
            //将时间字符串转化为NSDate
            let  createDate = NSDate.formatterDate(timeString, formatterString:"EEE MM dd HH:mm:ss Z yyyy")
            time = createDate.descriptionString()
        }

        /// 原创微博配图数组
        var array = [String]()
        for item in (dataModel?.pic_urls)!{
            let middleString  = item["thumbnail_pic"]!
//            middleString.replaceRange(middleString.rangeOfString("thumbnail")!, with: "bmiddle")

            array.append(middleString)
        }
        pictures_url = array

        
        ///转发微博配图数组
        if dataModel?.retweeted_status != nil {
            
            var arr = [String]()
            for item in (dataModel?.retweeted_status?.pic_urls)!{
                arr.append(item["thumbnail_pic"]!)
            }
            retweeted_picUrls = arr
        }

    }
    var pictures_url : [String]?
    
    
    var dataModel:CellDataModel?
    
    var iconImageURL : NSURL?
    
    var verifiedImage : UIImage?
    
    var time : String?
    
    var comeFromStirng : String?
    
    var ViplevelImage : UIImage?
    
    var retweeted_picUrls: [String]?
    
}
